﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using entity;
using DAL;

/// <summary>
///StockNoticeBLL 的摘要说明
/// </summary>
public class StockNoticeBLL
{
    public List<StockNotice> GetStockNoticeByStockId(string stockId)
    {
        StockNoticeDAL dal = new StockNoticeDAL();
        return dal.GetStockNoticeByStockId(stockId);
    }

    public string GetStockNoticeByStock(string stockId)
    {
        string key = "StockNoticeBLL_GetStockNoticeByStock:" + stockId;
        string str = (string)MemcachedTools.Get(key);
        if (!string.IsNullOrEmpty(str))
        {
            return str;
        }
        else
        {
            var lst = GetStockNoticeByStockId(stockId);
            str = Newtonsoft.Json.JsonConvert.SerializeObject(lst);
            MemcachedTools.Add(key, str, DateTime.Now.AddMinutes(30));
            return str;
        }
    }

    public string GetStockNoticeByDate(DateTime date)
    {
        string key = "StockNoticeBLL_GetStockNoticeByDate:" + date.ToString("yyyyMMdd");
        string str = (string)MemcachedTools.Get(key);
        if (!string.IsNullOrEmpty(str))
        {
            return str;
        }
        else
        {
            StockNoticeDAL dal = new StockNoticeDAL();
            var lst = dal.GetStockNoticeByDate(date);
            str = Newtonsoft.Json.JsonConvert.SerializeObject(lst);
            MemcachedTools.Add(key, str, DateTime.Now.AddMinutes(30));
            return str;
        }
    }

    public string GetNoticeById(long id)
    {
        string key = "StockNoticeBLL_GetNoticeById:" + id.ToString();
        string str = (string)MemcachedTools.Get(key);
        if (!string.IsNullOrEmpty(str))
        {
            return str;
        }
        else
        {
            StockNoticeDAL dal = new StockNoticeDAL();
            var c = dal.GetNoticeById(id);
            str = Newtonsoft.Json.JsonConvert.SerializeObject(c);
            MemcachedTools.Add(key, str, DateTime.Now.AddHours(10));
            return str;
        }
    }
}